package com.elvin.wx.controller;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.elvin.wx.beans.Employee;
import com.elvin.wx.service.EmployeeService;

import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xieyuxin
 * @since 2018-08-31
 */
@Controller
@RestController
@RequestMapping("/employeeController")
@ApiIgnore
public class EmployeeController {

	@Resource
	private EmployeeService employeeService;

	@ApiOperation(value = "获取所有用户")

	@PostMapping("/queryAll")
	public List<Employee> queryEmployees() {
		List<Employee> selectList = employeeService.selectList(null);

		return selectList;
	}

	@ApiOperation(value = "新增用户")

	@PostMapping("/insert")
	public Integer insert(@RequestBody Employee employee) {
		Employee employee2 = new Employee();
		employee2.setAge(employee.getAge());
		employee2.setGender(employee.getGender());
		employee2.setLastName(employee.getLastName());
		employee2.setEmail(employee.getEmail());
		employeeService.insert(employee2);
		return employee2.getId();
	}

	@ApiOperation(value = "修改用户")

	@PostMapping("/update")
	public boolean update(@RequestBody Employee employee) {
		Employee employee2 = new Employee();
		employee2.setAge(employee.getAge());
		employee2.setGender(employee.getGender());
		employee2.setLastName(employee.getLastName());
		employee2.setEmail(employee.getEmail());
		employee2.setId(employee.getId());
		boolean update = employeeService.updateById(employee2);
		//boolean update = employeeService.update(employee2, null);
		return update;
	}

	@ApiOperation(value = "删除用户")
	@PostMapping("/delete")
	public boolean delete(@RequestBody Integer id) {

		boolean update = employeeService.deleteById(id);
		return update;
	}
	
	@ApiOperation(value = "根据ID获取用户")

	@PostMapping("/getByid")
	public Employee getByid(@RequestBody Integer id) {

		Employee byid = employeeService.getByid(id);
		return byid;
	}
}

